function debound(fn, duration) {
  let timeId;
  return function (...arg) {
    clearTimeout(timeId);
    timeId = setTimeout(() => {
      fn.call(this, ...arg);
    }, duration);
  };
}

// function throttle(fn, duration) {
//   let endTime = 0;
//   return function (...arg) {
//     const now = Date.now();
//     if (now - endTime > duration) {
//       fn.call(this, ...arg);
//       endTime = now;
//     }
//   };
// }

function throttle(func, wait) {
  let arg, timeout;
  return function () {
    arg = argument;
    if (!timeout) {
      func.apply(this, arg);
      timeout = setTimeout(() => {
        timeout = null;
      }, wait);
    }
  };
}
